package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.itheima.domain.db.UserFreezing;
import com.itheima.mapper.FreezingMapper;
import com.itheima.service.db.FreezingService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class FreezingServiceImpl implements FreezingService {
    @Autowired
    private FreezingMapper freezingMapper;
    @Override
    public void saveFreezing(UserFreezing userFreezing) {
        freezingMapper.insert(userFreezing);
    }

    @Override
    public UserFreezing findById(Long userId) {
        QueryWrapper<UserFreezing> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        UserFreezing userFreezing = freezingMapper.selectOne(wrapper);
        System.out.println(userFreezing);
        return userFreezing;
    }

    @Override
    public void updateFreezing(UserFreezing userFreezing) {
        UpdateWrapper <UserFreezing>wrapper = new UpdateWrapper();
        wrapper.set("freezing_range", userFreezing.getFreezingRange());
        freezingMapper.update(userFreezing, wrapper);
    }

    @Override
    public UserFreezing findFreezing(Long userId, Integer freezingRange) {
        QueryWrapper<UserFreezing> wrapper = new QueryWrapper<>();
        wrapper.eq("freezing_range", freezingRange);
        wrapper.eq("user_id", userId);
        return freezingMapper.selectOne(wrapper);
    }

}
